package com.mnb.beidou.handler.impl;


import com.mnb.beidou.handler.TcpMessageHandler;
import com.mnb.beidou.model.PSDataEntity;
import com.mnb.beidou.service.Data2CParser;
import com.mnb.beidou.service.PSParser;
import com.mnb.beidou.utils.ByteUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 数据消息处理器
 */
@Component
public class DataMessageHandler implements TcpMessageHandler {

    private static final Logger logger = LoggerFactory.getLogger(DataMessageHandler.class);

    @Autowired
    private PSParser psParser;

    @Autowired
    private Data2CParser data2CParser;

    @Override
    public PSDataEntity handleMessage(String message) throws Exception {
        logger.info("收到数据消息: {}", message);
        // 这里可以添加数据处理逻辑，比如：
        // PS数据解析
        byte[] frame = ByteUtils.hexStringToByteArray(message);
        PSDataEntity psData = psParser.parse(frame);
        return psData;

    }

    @Override
    public String getSupportedMessageType() {
        return "TCP-DATA";
    }
}
